<template>
  <div class="app-container">

    <el-table :data="orderList" style="width: 100%">
      <el-table-column type="selection" prop="orderId" width="55">
      </el-table-column>
      <el-table-column prop="roomName" label="房型名称">
      </el-table-column>
      <el-table-column prop="user.userName" label="住户名称">
      </el-table-column>
      <el-table-column prop="user.tel" label="联系电话" >
      </el-table-column>
      <el-table-column prop="startDate" label="入住时间">
        <template slot-scope="scope">
          {{scope.row.startDate | dataformat}}
        </template>
      </el-table-column>
      <el-table-column prop="leaveDate" label="离店时间">
         <template slot-scope="scope">
          {{scope.row.leaveDate | dataformat}}
        </template>
      </el-table-column>
       <el-table-column prop="remark" label="备注">
      </el-table-column>
       <el-table-column label="操作">
         <!-- 用户详情信息 -->
         <template slot-scope="scope">
             <el-button
              type="primary"
              icon="el-icon-del"
              @click="
                details(scope.row);
              "
            >详情信息</el-button>
         </template>
      </el-table-column>
    </el-table>
    <el-pagination
      style="float: right"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-sizes="[3, 4, 5, 6]"
      :page-size="orderentity.limit"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
<!-- 显示用户详情 -->
    <el-dialog title="用户详情"  :visible.sync="dialogFormVisible">
  <el-form :model="userEntity">
    <el-form-item label="用户名" prop="userName">
      <el-input autocomplete="off" v-model="userEntity.userName" readonly ></el-input>
    </el-form-item>
   <el-form-item label="用户邮箱" prop="email">
      <el-input v-model="userEntity.email" autocomplete="off" readonly></el-input>
    </el-form-item>
    <el-form-item label="联系电话" prop="tel">
      <el-input v-model="userEntity.tel" autocomplete="off" readonly></el-input>
    </el-form-item>
  </el-form>
</el-dialog>
  
  </div>
</template>
<style>
.avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
<script>
import {listOrder,detailsByuserId} from "@/api/order";
export default {
  data() {
    return {
    total:0,
      dialogFormVisible: false,
      orderentity: {
        page:1,
        limit:3,
        data:{
        }
      },
      orderList: [],
      userEntity:{}
    };
  },
  methods: {
    // 查询商户订单信息
    search() {
      let _this = this;
      listOrder(this.orderentity).then(res=>{
          // console.log(res);
          _this.orderList = res.data;
          _this.total = res.total;
      })
    },
    // 获取订单用户详情信息
    details(row){
      let _this = this;
      this.userEntity = {};
      this.dialogFormVisible = true;
      detailsByuserId(row.userId).then(res=>{
          _this.userEntity = res.data;
          console.log( _this.userEntity)
      })
    },
    // 修改当前页面
    handleCurrentChange(val){
        this.orderentity.page = val;
        this.search();
    },
    handleSizeChange(val){
      this.orderentity.limit = val;
      this.search();
    },
  },
  created() {
    this.search();
  },
  filters: {
    dataformat(originVal){
       const dt = new Date(originVal)
        let y = dt.getFullYear()
        let m = (dt.getMonth() + 1 + '').padStart(2, '0')
        let d = (dt.getDate() + '').padStart(2, '0')

        let hh = (dt.getHours() + '').padStart(2, '0')
        let mm = (dt.getMinutes() + '').padStart(2, '0')
        // yyyy-mm-dd hh:mm:ss
        return `${y}-${m}-${d} ${hh}:${mm}`
    },
  },
};
</script>